﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

// Added using statements
using Microsoft.BizTalk.Component.Interop;
using Microsoft.BizTalk.Message.Interop;
using System.Drawing;
using System.Resources;
using System.Reflection;

namespace XMLReceiveCBR.PipelineComponents
{
    [ComponentCategory(CategoryTypes.CATID_PipelineComponent)]
    [ComponentCategory(CategoryTypes.CATID_Any)]
    [ComponentCategory(CategoryTypes.CATID_Validate)]
    [System.Runtime.InteropServices.Guid("68BEC85A-20EE-40ad-BFD0-319B59A0DDBC")]
    public class PromotePropertiesCBR : IBaseComponent, IComponent, IComponentUI
    {
        static ResourceManager resManager =
            new ResourceManager("XMLReceiveCBR.PipelineComponents.PromotePropertiesCBR", Assembly.GetExecutingAssembly());

        #region IBaseComponent Members

        public string Description
        {
            get { return "Promote CBR Properties Pipeline Component"; }
        }

        public string Name
        {
            get { return "Promote CBR Properties Component"; }
        }

        public string Version
        {
            get { return "1.0"; }
        }

        #endregion

        #region IComponent Members

        public IBaseMessage Execute(IPipelineContext pContext, IBaseMessage pInMsg)
        {
            string strNameSpace = "http://schemas.microsoft.com/BizTalk/2003/system-properties";
            object value = pInMsg.Context.Read("EpmRRCorrelationToken", strNameSpace);
            if (value != null)
            {
                string empToken = (string)value;
                bool directToTP = true;
                pInMsg.Context.Promote("EpmRRCorrelationToken", strNameSpace, empToken);
                pInMsg.Context.Promote("RouteDirectToTP", strNameSpace, directToTP);
            }
            return pInMsg;
        }

        #endregion

        #region IComponentUI Members

        public IntPtr Icon
        {
            get { return ((Bitmap)resManager.GetObject("PromotePropertiesCBRBitmap")).GetHicon(); }
        }

        public System.Collections.IEnumerator Validate(object projectSystem)
        {
            return null;
        }

        #endregion
    }
}
